<?php

session_start();
   
   $_SESSION['list'] = $_GET['choice'];


$conn = mysql_connect('studentdb.gl.umbc.edu', 'chrimo1', 'chrimo1');
if (!$conn) {
   die('Could not connect');
}

$db_selected = mysql_select_db('chrimo1', $conn);
if (!$db_selected) {
   die ('Can\'t use chrimo1');
}

?>
<html>
   <head>
      <a style="color:gold" href="admin.html"><img src="images/admin_button.png"></a>
      <center><h1>Game Inventory</h1></center>

      <style type="text/css">

        body{
	   background-color: black;
          color: gold;
          font-size: 14pt;
        }

      </style>
      
   </head>
   <body>

   
   

<?php
$choice = $_GET['choice'];


if ($choice == all){  

  $sql = "SELECT * FROM gameInventory ORDER BY gameName";
  $result = mysql_query($sql, $conn);
  if (mysql_num_rows($result) == 0 ) {
    echo '<center><h2>There are no games in Inventory</h2></center>';
    echo '<center><a style="color:gold" href="admin.html"><img src="images/admin_button.png"></a></center>';
    die();
  }
    
  echo '<center>';
  echo '<form action="editInventory.php" method="post">';

    
    echo '<table border="1">';
	echo '<tr><th></th><th>Game Name</th><th>System</th><th>Developer</th><th>Release Date</th><th>Qty</th><th>Price</th></tr>';

    while($r = mysql_fetch_array($result))
    {
             
       echo '<tr>';
         echo '<td > <input type="radio" name="idNum" value="'; echo $r['idNum']; echo '"></td>'; 
         echo '<td width="40%">'; echo $r[gameName]; echo '</td>';
	  if($r[system] == 'sega'){
	    echo '<td width="15%">Sega Genesis</td>';
	  }
	  else if($r[system] == 'snes'){
	    echo '<td width="15%">Super Nintendo</td>';
	  }
	  else{
	    echo '<td width="15%"></td>';
	  }
	  echo '<td width="20%">';echo $r[developer];echo '</td>';

	  if($r[releaseDate] == 0){
	    echo '<td align="center" width="10%">';echo '<font color="red">'; echo $r[releaseDate]; echo '</font>'; echo '</td>';
	  }
	  else{
	    echo '<td align="center" width="10%">';echo $r[releaseDate];echo '</td>';
	  }

	  if($r[quantity] == 0){
           echo '<td align="right" width="5%">';echo '<font color="red">'; echo $r[quantity]; echo '</font>'; echo '</td>';
         }
	  else{
	    echo '<td align="right" width="5%">'; echo $r[quantity]; echo '</td>';
	  }
	  
	  if($r[price] == 0){
	    echo '<td align="right" width="10%">';echo '<font color="red">'; echo $r[price]; echo '</font>'; echo '</td>';
	  }
	  else{
	    echo '<td align="right" width="10%">'; echo $r[price]; echo '</td>';
	  }
       echo '</tr>';
    }

    echo '</table>';
    echo '<input type="submit" name="edit" value="Edit" style="height: 25px; width: 100px; font-size: 15; font-weight: bold"> ';
    echo '<input type="submit" name="delete" value="Delete" onclick="return confirm(\'Are you sure you want to delete this game?\')" style="height: 25px; width: 100px; font-size: 15; font-weight: bold">';
  echo '</form>';
  echo '</center>';

}
elseif ($choice == snes){

  echo '<center><img src="images/SNES_logo.jpg" alt="SNES icon" /></center>';

  $sql = "SELECT * FROM gameInventory WHERE system='snes' ORDER BY gameName";
  $result = mysql_query($sql, $conn);
  if (mysql_num_rows($result) == 0 ) {
    echo '<center><h2>There are no Super Nintendo games in Inventory</h2></center>';
    echo '<center><a style="color:gold" href="admin.html">BACK</a></center>';
    die();
  }

  echo '<center>';
  echo '<form action="editInventory.php" method="post">';

    echo '<table border="1">';
      echo '<tr>';
      echo '<th></th><th>Game Name</th><th>Developer</th><th>Release Date</th><th>Qty</th><th>Price</th>';
      echo '</tr>';
 

    while($r = mysql_fetch_array($result))
    {
       echo '<tr>';
         echo '<td> <input type="radio" name="idNum" value="'; echo $r['idNum']; echo '"></td>'; 
         echo '<td width="40%">';echo $r['gameName'];echo '</td>';
         echo '<td width="28%">';echo $r['developer'];echo '</td>';

         if($r[releaseDate] == 0){
	    echo '<td align="center" width="10%">';echo '<font color="red">'; echo $r[releaseDate]; echo '</font>'; echo '</td>';
	  }
	  else{
	    echo '<td align="center" width="10%">';echo $r[releaseDate];echo '</td>';
	  }

	  if($r['quantity'] == 0){
           echo '<td align="right" width="5%">';echo '<font color="red">'; echo $r['quantity']; echo '</font>'; echo '</td>';
         }
	  else{
	    echo '<td align="right" width="5%">'; echo $r['quantity']; echo '</td>';
	  }
	  
	  if($r[price] == 0){
	    echo '<td align="right" width="10%">';echo '<font color="red">'; echo $r[price]; echo '</font>'; echo '</td>';
	  }
	  else{
	    echo '<td align="right" width="10%">'; echo $r[price]; echo '</td>';
	  }         
       echo '</tr>';
    }

    echo '</table>';
    echo '<input type="submit" name="edit" value="Edit" style="height: 25px; width: 100px; font-size: 15; font-weight: bold"> ';
    echo '<input type="submit" name="delete" value="Delete" onclick="return confirm(\'Are you sure you want to delete this game?\')" style="height: 25px; width: 100px; font-size: 15; font-weight: bold">';
  echo '</form>';
  echo '</center>';

}
elseif ($choice == sega){

  echo '<center><img src="images/Sega-Genesis-Logo.jpg" alt="SEGA icon" /></center>';

  $sql = "SELECT * FROM gameInventory WHERE system='sega' ORDER BY gameName";
  $result = mysql_query($sql, $conn);
  if (mysql_num_rows($result) == 0 ) {
    echo '<center><h2>There are no Sega Genesis games in Inventory</h2></center>';
    echo '<center><a style="color:gold" href="admin.html">BACK</a></center>';
    die();
  }

  echo '<center>';
  echo '<form action="editInventory.php" method="post">';

    echo '<table border="1">';
      echo '<tr>';
      echo '<th></th><th>Game Name</th><th>Developer</th><th>Release Date</th><th>Qty</th><th>Price</th>';
      echo '</tr>';
 

    while($r = mysql_fetch_array($result))
    {

       echo '<tr>';
         echo '<td> <input type="radio" name="idNum" value="'; echo $r['idNum']; echo '"></td>'; 
         echo '<td width="40%">';echo $r['gameName'];echo '</td>';
         echo '<td width="28%">';echo $r['developer'];echo '</td>';

         if($r[releaseDate] == 0){
	    echo '<td align="center" width="10%">';echo '<font color="red">'; echo $r[releaseDate]; echo '</font>'; echo '</td>';
	  }
	  else{
	    echo '<td align="center" width="10%">';echo $r[releaseDate];echo '</td>';
	  }

	  if($r['quantity'] == 0){
           echo '<td align="right" width="5%">';echo '<font color="red">'; echo $r['quantity']; echo '</font>'; echo '</td>';
         }
	  else{
	    echo '<td align="right" width="5%">'; echo $r['quantity']; echo '</td>';
	  }

	  if($r[price] == 0){
	    echo '<td align="right" width="10%">';echo '<font color="red">'; echo $r[price]; echo '</font>'; echo '</td>';
	  }
	  else{
	    echo '<td align="right" width="10%">'; echo $r[price]; echo '</td>';
	  }
       echo '</tr>';
    }

    echo '</table>';
    echo '<input type="submit" name="edit" value="Edit" style="height: 25px; width: 100px; font-size: 15; font-weight: bold"> ';
    echo '<input type="submit" name="delete" value="Delete" onclick="return confirm(\'Are you sure you want to delete this game?\')" style="height: 25px; width: 100px; font-size: 15; font-weight: bold">';
  echo '</form>';
  echo '</center>';

}
?>
   </body>
</html>